﻿using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Linq.Expressions;
using System.Reactive;
using System.Reactive.Concurrency;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using System.Reactive.Subjects;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace SimpleActor.Test
{
    [TestClass]
    public class CompiledExpressionInfoTest
    {
        [TestMethod]
        public void ConstructorTest()
        {
            AssertEx.Throws<ArgumentNullException>(() =>
            {
                Expression<Func<ITestServant, Task>> action = null;
                new CompiledExpressionInfo<Func<ITestServant, Task>>(action);
            });

            AssertEx.Throws<ArgumentException>(() =>
            {
                Expression<Func<ITestServant, Task>> action = s => s.Action1(0);
                new CompiledExpressionInfo<Func<ITestServant, Task>>(action);
            });
        }

        [TestMethod]
        public void MemberNameTest()
        {
            Expression<Func<ITestServant, Task>> action = s => s.Action0();

            var obj = new CompiledExpressionInfo<Func<ITestServant, Task>>(action);
            obj.MemberName.Is("Action0");
        }

        [TestMethod]
        public void ExpressionTypeTest()
        {
            Expression<Func<ITestServant, Task>> action = s => s.Action0();

            var obj = new CompiledExpressionInfo<Func<ITestServant, Task>>(action);
            obj.ExpressionType.Is(typeof(Expression<Func<ITestServant, Task>>));
        }
    }

    [TestClass]
    public class CompiledExpressionCacheTest
    {
        [TestMethod]
        public void GetTest()
        {
            AssertEx.Throws<ArgumentNullException>(() =>
            {
                Expression<Func<ITestServant, Task>> action = null;
                var info = CompiledExpressionCache.Get(action);
            });

            AssertEx.Throws<ArgumentException>(() =>
            {
                Expression<Func<ITestServant, Task>> action = s => s.Action1(0);
                var info = CompiledExpressionCache.Get(action);
            });
        }
    }
}
